package pub.strawhat.album.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.github.pagehelper.PageInfo;
import pub.strawhat.album.model.FileVO;
import pub.strawhat.album.model.TopicsVO;
import pub.strawhat.album.service.FileService;
import pub.strawhat.album.service.TopicsService;

@Controller
public class PhotoController {
	@Autowired
	private FileService fileService;
	@Autowired
	private TopicsService topicsService;

	@GetMapping(value = "admin/photo/list")
	public String list(Model model) {
		model.addAttribute("active", "photo");
		return "admin/photo/list";
	}
	
	@GetMapping(value = "admin/photo/view/{id}")
	public String view(@PathVariable("id") Integer id, Model model) {
		TopicsVO topics = topicsService.findTopicsById(id);
		List<FileVO> photos = fileService.findFileListByBatchId(id);
		model.addAttribute("topics", topics);
		model.addAttribute("photos", photos);
		return "admin/photo/view";
	}

	@ResponseBody
	@GetMapping(value = "admin/photo/page")
	public PageInfo<FileVO> page(@RequestParam("pageSize") Integer pageSize, @RequestParam("pageNum") Integer pageNum,
			FileVO fileVO) {
		PageInfo<FileVO> page = fileService.findFileList(fileVO, pageNum, pageSize);
		return page;
	}

	@ResponseBody
	@GetMapping(value = "admin/photo/delete/{batchId}/{fileId}")
	public Boolean del(@PathVariable("batchId") Integer batchId, @PathVariable("fileId") Integer fileId) {
		return fileService.delFile(batchId, fileId);
	}

}